<template>
  <div class="login">
    <div class="loginbox">
      <div class="loginimg">
        <img :src="lo" />
      </div>
      <div class="loginss">
        <h3>评价系统</h3>
        <el-form ref="form" :model="form" label-width="80px" label-position="top" class="fromtxt">
          <el-form-item label="用户名">
            <el-input placeholder="请输入用户名" v-model="form.loginName"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input placeholder="请输入密码" v-model="form.password" @keyup.native.enter="dologin" type="password"></el-input>
          </el-form-item>
          <el-form-item label=" ">
            <el-button type="primary" @click="dologin" style="width: 100%;">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

 <script>
import lo from "@/assets/123.png";

import { getLogin } from "../api/api";

export default {
  data() {
    return {
      lo: lo,
      input: "",
      form: {
        password: "",
        loginName: "",
      },
    };
  },
  mounted() {
  },
  methods: {
    async dologin() {
      let that = this;
      let params = that.form;
      let res = await getLogin(params);
      if (res.data.Code == 200) {
        // res.data.access_token
        localStorage.setItem("token", res.data.Data.token);
        localStorage.setItem(
          "userinfo",
          JSON.stringify(res.data.Data.userinfo)
        );

        if (res.data.Data.userinfo.role == "1") {
          this.$router.push({
            path: "/bumen",
            query: {},
          });
          return;
        }else if(res.data.Data.userinfo.role=="4"){
          this.$router.push({
            path: "/questionnaire",
            query: {},
          });
        }
        else{
          this.$router.push({
            path: "/personnel",
            query: {},
          });
          return;
        }
      } else if (res.data.Code == 400) {
        this.$message({
          type: "info",
          message: res.data.Msg,
        });
        return;
      }
    },
  },
};
</script>

<style scoped>
.login {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  background: #aac9ff;
}
.loginbox {
  width: 859px;
  background: #fff;
  margin: 0 auto;
  height: 518px;
  position: relative;
  right: 0;
  left: 0;
  z-index: 1;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 18px;
  display: flex;
}
.loginimg {
  height: 100%;
}
.loginimg img {
  height: 100%;
}
.loginss {
  text-align: center;
  width: 100%;
}
.loginss h3 {
  line-height: 60px;
  margin-top: 30px;
  font-size: 26px;
}
.fromtxt {
  text-align: left;
  width: 60%;
  margin: 0 auto;
}
</style>